//
//  NSString+Extension.m
//  Test
//
//  Created by Ares on 14-1-6.
//  Copyright (c) 2014年 Ares. All rights reserved.
//

#import "NSString+Extension.h"

@implementation NSString (Extension)

+(CGRect)heightForString:(NSString*)str Size:(CGSize)size Font:(UIFont*)font Lines:(int)lines
{
    if (StringIsNullOrEmpty(str)) {
        return CGRectMake(0, 0, 0, 0);
    }
    static UILabel *lbtext;
    if (lbtext==nil) {
        lbtext = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
    }else{
        lbtext.frame=CGRectMake(0, 0, size.width, size.height);
    }
    lbtext.font=font;
    lbtext.text=str;
    lbtext.numberOfLines=lines;
    lbtext.lineBreakMode = NSLineBreakByWordWrapping;
    lbtext.textAlignment = NSTextAlignmentLeft;
    CGRect rect= [lbtext textRectForBounds:lbtext.frame limitedToNumberOfLines:lines];
    if(rect.size.height<0)
        rect.size.height=0;
    if (rect.size.width<0) {
        rect.size.width=0;
    }
    return rect;
    
}
@end
